﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smarly.Bussines.Membership;
using Smarly.Web.Controllers;

namespace Smarly.Web.Areas.Admin.Controllers
{
	public class AdminAuthorizeAttribute : AuthorizeAttribute
	{
		protected override bool AuthorizeCore(HttpContextBase httpContext)
		{
			var result = base.AuthorizeCore(httpContext);
			if (!result)
			{
				var hashTag = httpContext.Request.Params[EditorParam];
				SmarlyPrincipal user = (SmarlyPrincipal)httpContext.User;
				result = user.AllowChanges(hashTag);
			}
			return result;
		}

		public string EditorParam { set; get; }
	}
}
